package controller

import (
	"ollama-go/dto"
	"ollama-go/query"
	"ollama-go/service"

	"github.com/androidsr/sc-go/model"
	"github.com/androidsr/sc-go/sgin"
	"github.com/gin-gonic/gin"
)

func init() {
	sgin.AddRouter(OllamaRolesController{
		ollamaRolesService: service.NewOllamaRolesService(),
	})
}

type OllamaRolesController struct {
	ollamaRolesService *service.OllamaRolesService
}

// 查询
// @Router [get] [/roles/:id]
func (m OllamaRolesController) Get(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.ollamaRolesService.Get(id)
}

// 增加
// @Router [post] [/roles]
func (m OllamaRolesController) Save(c *gin.Context, dto *dto.OllamaRolesDTO) any {
	dto.Id = ""
	dto.TenantId = c.GetString(USER)
	return m.ollamaRolesService.Save(dto)
}

// 修改
// @Router [put] [/roles/edit]
func (m OllamaRolesController) UpdateById(c *gin.Context, dto *dto.OllamaRolesDTO) any {
	if dto.Id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	dto.TenantId = c.GetString(USER)
	return m.ollamaRolesService.UpdateById(dto)

}

// 删除
// @Router [delete] [/roles/:id]
func (m OllamaRolesController) DeleteById(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.ollamaRolesService.DeleteById(id)
}

// 查询列表
// @Router [post] [/roles/page]
func (m OllamaRolesController) QueryPage(c *gin.Context, query *query.OllamaRolesQueryDTO) any {
	query.TenantId = c.GetString(USER)
	return m.ollamaRolesService.QueryPage(query)
}

// 分页下拉
// @Router [post] [/roles/list]
func (m OllamaRolesController) QuerySelect(c *gin.Context, query *model.SelectQueryDTO) any {
	if query.Vars == nil {
		query.Vars = make(map[string]interface{})
	}
	query.Vars["tenant_id"] = c.GetString(USER)
	return m.ollamaRolesService.QueryList(query)
}
